package view;

import java.io.IOException;
import java.util.Hashtable;

import javax.management.RuntimeErrorException;

import model.Category;
import model.Present;
import model.PresentDistributor;
import model.PresentDistributorImpl;


public class Test {
	public static void main(String[] args) throws IOException, ClassNotFoundException{
		test2();
	}
	private static void test2(){
		PresentDistributor foo = new PresentDistributorImpl();
		foo.addParticipant("Timo", Category.MALE);
		foo.addParticipant("Kat", Category.FEMALE);
		foo.addParticipant("Eddi", Category.MALE);
		foo.addParticipant("Janne", Category.FEMALE);
		foo.addParticipant("Walter", Category.MALE);
		foo.addParticipant("Wilfried", Category.MALE);
		foo.addParticipant("Christian", Category.MALE);
		foo.addParticipant("Sara", Category.FEMALE);
		foo.addParticipant("Alex", Category.FEMALE);
		foo.addParticipant("Gabi", Category.FEMALE);
		foo.addParticipant("Konni", Category.MALE);
		
		
		foo.addPresent(0, new String[]{"Walter","Wilfried","Eddi"});
		foo.addPresent(1, new String[]{"Gabi", "Janne", "Alex", "Sara","Kat"});
		foo.addPresent(2, new String[]{"Timo","Christian"});
		foo.addPresent(3, new String[]{"Eddi","Konni","Wilfried"});
		foo.addPresent(4, new String[]{"Sara", "Kat", "Alex"});
		foo.addPresent(5, new String[]{"Walter", "Wilfried","Konni"});
		foo.addPresent(6, new String[]{"Janne", "Gabi","Sara","Timo"});
		foo.addPresent(7, new String[]{"Timo", "Kat","Alex"});
		foo.addPresent(8, new String[]{"Eddi","Walter","Wilfried","Christian","Timo","Konni"});
		foo.addPresent(9, new String[]{"Timo", "Kat","Sara"});
		foo.addPresent(10, new String[]{"Eddi","Wilfried","Janne"});
		System.out.println(foo);
		System.out.println("Valid distro:"+foo.isValidDistribution());
		System.out.println("###Leute ohne Geschenk:");
		for(String name : foo.getParticipantsWithoutPresents()){
			System.out.println(name);
		}
		System.out.println("###");
		Hashtable<String, Present> bar = foo.getPresentDistribution();
		if(bar == null){
			throw new RuntimeException("no valid solution available");
		}
		for(String s : bar.keySet()){
			System.out.println(s+"->"+bar.get(s).getNumber());
		}
		
	}

	private static void test1() {
		PresentDistributor foo = new PresentDistributorImpl();
		foo.addParticipant("Timo", Category.MALE);
		foo.addParticipant("Kat", Category.FEMALE);
		foo.addParticipant("Eddi", Category.MALE);
		foo.addParticipant("Janne", Category.FEMALE);
		foo.addParticipant("Tina", Category.FEMALE);
		foo.addParticipant("Frank", Category.MALE);
		foo.addParticipant("Rebecca", Category.FEMALE);
		foo.addParticipant("Walter", Category.MALE);
		foo.addParticipant("Wilfried", Category.MALE);
		foo.addParticipant("Christian", Category.MALE);
		foo.addParticipant("Sara", Category.FEMALE);
		foo.addParticipant("Alex", Category.FEMALE);
		foo.addParticipant("Gabi", Category.FEMALE);
		foo.addParticipant("Konni", Category.MALE);
		foo.addParticipant("Oma", Category.FEMALE);
		
		
		foo.addPresent(0, new String[]{"Timo","Kat"});
		foo.addPresent(1, new String[]{"Timo","Konni","Eddi"});
		foo.addPresent(2, new String[]{"Christian","Janne","Tina","Sara"});
		foo.addPresent(3, new String[]{"Walter","Konni","Wilfried"});
		foo.addPresent(4, new String[]{"Tina","Frank"});
		foo.addPresent(5, new String[]{"Rebecca","Kat","Frank"});
		foo.addPresent(6, new String[]{"Timo","Gabi","Eddi"});
		foo.addPresent(7, new String[]{"Janne","Gabi","Tina"});
		foo.addPresent(8, new String[]{"Janne","Walter","Wilfried"});
		foo.addPresent(9, new String[]{"Christian","Sara","Eddi"});
		foo.addPresent(10, new String[]{"Frank","Tina","Eddi"});
		foo.addPresent(11, new String[]{"Timo","Wilfried","Walter"});
		foo.addPresent(12, new String[]{"Timo","Konni","Eddi"});
		foo.addPresent(13, new String[]{"Timo","Konni","Eddi"});
		foo.addPresent(14, new String[]{"Oma", "Alex"});
		System.out.println(foo);
		System.out.println("Valid distro:"+foo.isValidDistribution());
		System.out.println("###Leute ohne Geschenk:");
		for(String name : foo.getParticipantsWithoutPresents()){
			System.out.println(name);
		}
		System.out.println("###");
		Hashtable<String, Present> bar = foo.getPresentDistribution();
		if(bar == null){
			throw new RuntimeException("no valid solution available");
		}
		for(String s : bar.keySet()){
			System.out.println(s+"->"+bar.get(s).getNumber());
		}
//		foo.savePresents(new File("./serialized.txt"));
//		foo.loadPresents(new File("./serialized.txt"));
//		for(String name : foo.getAllParticipants()){
//			System.out.println(name);
//		}
	}
}
